import { RequestType, ResponseType } from './utils';

// Common Response Type
export interface ApiResponse<T = any> {
  code: number;
  message: string;
  data: T;
}

// Error Types
export interface ApiError {
  code: number;
  message: string;
  details?: any;
}

// Pagination Types
export interface PaginationParams {
  page: number;
  pageSize: number;
}

export interface PaginatedResponse<T> {
  list?: T[];
  total: number;
}

// Auth Types
export interface LoginRequest {
  email: string;
  password: string;
  verificationCode?: string;
}

export interface LoginResponse {
  token: string;
  refreshToken: string;
  user: {
    id: string;
    email: string;
    username: string;
    role: string;
    status: 'active' | 'inactive';
  };
}

// User Types
export interface UserProfile {
  id: string;
  email: string;
  username: string;
  role: string;
  status: 'active' | 'inactive';
  createdAt: string;
  lastLoginAt: string;
  googleAuthEnabled: boolean;
  emailVerified: boolean;
}

export interface UpdateProfileRequest {
  username?: string;
  avatar?: string;
  timezone?: string;
  language?: string;
}

export interface ChangePasswordRequest {
  oldPassword: string;
  newPassword: string;
  verificationCode: string;
}

export interface ChangeEmailRequest {
  newEmail: string;
  verificationCode: string;
}

// Card Types
export interface CardSegment {
  id: string;
  name: string;
  status: 'active' | 'inactive';
  cardType: string;
  description?: string;
  createdAt: string;
}

export interface DebitAccount {
  id: string;
  name: string;
  balance: string;
  currency: string;
  status: 'active' | 'frozen' | 'closed';
  type: 'personal' | 'business';
  createdAt: string;
}

export interface CardTag {
  id: string;
  name: string;
  discount: number;
  minPurchase: number;
  maxDiscount?: number;
  startDate: string;
  expiresAt: string;
  status: 'active' | 'expired';
}

// Transaction Types
export interface Transaction {
  id: string;
  cardNumber: string;
  cardPosition: string;
  amount: string;
  status: 'pending' | 'completed' | 'failed';
  type: 'online' | 'offline';
  transactionTime: string;
  completionTime: string;
  merchantAmount: string;
  merchantCurrency: string;
  originalAmount: string;
  exchangeRate?: string;
  reason?: string;
  description?: string;
  tags: string[];
  metadata?: Record<string, any>;
}

export interface TransactionQueryParams extends PaginationParams {
  startDate?: string;
  endDate?: string;
  cardNumber?: string;
  status?: string;
  type?: string;
  minAmount?: number;
  maxAmount?: number;
}

export interface TransactionStats {
  totalCount: number;
  totalAmount: string;
  pendingCount: number;
  pendingAmount: string;
  completedCount: number;
  completedAmount: string;
  failedCount: number;
  failedAmount: string;
  currency: string;
}

// Refund Types
export interface Refund {
  id: string;
  transactionId: string;
  cardNumber: string;
  cardPosition: string;
  amount: string;
  status: 'pending' | 'completed' | 'rejected';
  reason: string;
  description?: string;
  requestedAt: string;
  completedAt?: string;
  rejectedAt?: string;
  rejectionReason?: string;
}

export interface RefundQueryParams extends PaginationParams {
  startDate?: string;
  endDate?: string;
  cardNumber?: string;
  status?: string;
}

// Balance Log Types
export interface BalanceLog {
  after: number;
  amount: number;
  before: number;
  createdAt: number;
  createdAtString: string;
  daily: number;
  describe: string;
  id: number;
  memberId: number;
  remark: string;
  scene: number;
  sceneString: string;
  status: number;
  statusString: string;
  track: string;
  trackId: number;
  transactionId: number;
  transactionNo: string;
  updatedAt: number;
  updatedAtString: string;
  walletType: number;
}

export interface BalanceLogQueryParams {
  page: number;
  pageSize: number;
  logScene?: number;
}

export interface BalanceLogResponse {
  list: BalanceLog[];
  total: number;
}

// Card Transaction Types
export interface CardTransaction {
  id: number;
  cardId: number;
  memberId: number;
  transactionTime: string;
  transactionType: string;
  transactionStatus: string;
  transactionAmount: number;
  transactionCurrency: string;
  billingAmount: number;
  billingCurrency: string;
  transactionFee: number;
  cardAvailableBalance: number;
  failureReason: string;
  authorizationCode: string;
  merchantData: string;
  postedTime: string;
  createdAt: number;
  createdAtString: string;
  updatedAt: number;
  updatedAtString: string;
}

export interface CardTransactionQueryParams {
  page: number;
  pageSize: number;
  cardId?: number;
  transactionStatus?: 'APPROVED' | 'DECLINED';
  transactionType?: 'AUTHORIZATION' | 'REFUND' | 'REVERSAL';
}

export interface CardTransactionResponse {
  list: CardTransaction[];
  total: number;
}

// Config Types
export interface Config {
  id: number;
  title: string;
  name: string;
  type: string;
  value: string;
  remark: string;
  sort: number;
  status: number;
  createdAt: number;
  updatedAt: number;
}

export interface ConfigResponse {
  code: number;
  message: string;
  data: Config[];
}

// 使用工具类型来转换请求和响应类型
export type ApiLoginRequest = RequestType<LoginRequest>;
export type ApiLoginResponse = ResponseType<LoginResponse>;
export type ApiPaginationParams = RequestType<PaginationParams>;
export type ApiPaginatedResponse<T> = ResponseType<PaginatedResponse<T>>;